package pucp.carpooling.adapter;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.actionbarsherlock.app.SherlockFragment;
import pucp.carpooling.R;

public class ListViewAdapterPasajero extends BaseAdapter {

	// Declare Variables
	Context context;
	String[] rank;
	Date d;
	String[] country;
	String[] population;
	int[] flag;
	LayoutInflater inflater;

	public ListViewAdapterPasajero(Context context, String[] rank, String[] country,
			String[] population, int[] flag) {
		this.context = context;
		this.rank = rank;
		this.country = country;
		this.population = population;
		this.flag = flag;
	}

	public int getCount() {
		return rank.length;
	}

	public Object getItem(int position) {
		return null;
	}

	public long getItemId(int position) {
		return 0;
	}

	public View getView(int position, View convertView, ViewGroup parent) {

		// Declare Variables
		TextView txtrank;
		TextView txtcountry;
		TextView txtpopulation;
		ImageView imgflag;

		inflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

		View itemView = inflater.inflate(R.layout.listview_item_avisos_pasajero, parent, false);

		
		txtrank = (TextView) itemView.findViewById(R.id.txtPasajero);
		txtcountry = (TextView) itemView.findViewById(R.id.txtDestinoPasajero);
		txtpopulation = (TextView) itemView.findViewById(R.id.txtFechaPasajero);
		imgflag = (ImageView) itemView.findViewById(R.id.flagpasajero);

		// Capture position and set to the TextViews
		txtrank.setText(rank[position]);
		txtcountry.setText(country[position]);
		
		SimpleDateFormat formatoIn = new SimpleDateFormat("yyyy-MM-dd HH:mm");
		SimpleDateFormat formatoOutFecha = new SimpleDateFormat("dd-MM-yyyy  HH:mm");
	//	SimpleDateFormat formatoOutHora = new SimpleDateFormat("HH:mm");
		String fechita = population[position];
		
		try {
			d = (Date) formatoIn.parse(fechita);
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
		
		txtpopulation.setText(formatoOutFecha.format(d));

		// Capture position and set to the ImageView
		imgflag.setImageResource(flag[position]);

		return itemView;
	}
}
